package com.sys.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class DownloadUtils {

	public static String getDownloadFileName(String filename, String agent)
			throws UnsupportedEncodingException {
		if(agent.contains("Edge")) {
			filename = URLEncoder.encode(filename, "utf-8");
			filename = filename.replace("%28", "(");
			filename = filename.replace("%29", ")");
			filename = filename.replace("+", " ");
			filename = filename.replace("%2B", "+");
			filename = filename.replace("%5B", "[");
			filename = filename.replace("%5D", "]");
		}
		else if (agent.contains("MSIE")) {
			// IE浏览器
			filename = URLEncoder.encode(filename, "utf-8");
			filename = filename.replace("+", " ");
		} else if (agent.contains("Firefox")) {
			// 火狐浏览器
			filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");
		} else if (agent.contains("Chrome")) {
			// google浏览器
			filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");
		} else {
			// 其它浏览器
			filename = URLEncoder.encode(filename, "utf-8");
		}
		return filename;
	}
}
